Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(), //day
        "h+": this.getHours(), //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
        "S": this.getMilliseconds() //millisecond
    }

    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1,
            (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }

    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1,
                RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(
                    ("" + o[k]).length));
        }
    }
    return format;
};

var imageSrc = '..'

$(window).resize(function() {
	renderGeneralPublicSentiment();
});
// 舆情分析总体
function renderGeneralPublicSentiment () {
	var winWidth = window.innerWidth;
    var strokeWidth = winWidth > 2561 ? 20 : 10;
    var width = winWidth > 2561 ? 236 : 118;
	var relativeStrokeWidth = (strokeWidth / width * 100).toFixed(1);

	function getPerimeter () {
		var radius = 50 - parseFloat(relativeStrokeWidth) / 2;
		return 2 * Math.PI * radius;
	}

	function getTrackPath () {
		var radius = parseInt(50 - parseFloat(relativeStrokeWidth) / 2, 10);
		return 'M 50 50 m 0 -' + radius + ' a ' + radius + ' ' + radius + ' 0 1 1 0 ' + (radius * 2) + ' a ' + radius + ' ' + radius + ' 0 1 1 0 -' + (radius * 2);
	}

	function getCirclePathStyle (percentage) {
		percentage = percentage || 0
		if (percentage < 0) {
			percentage = 0;
		} else if (percentage > 100) {
			percentage = 100;
		}
		var perimeter = getPerimeter();
		return {
			strokeDasharray: perimeter + 'px, ' + perimeter + 'px',
			strokeDashoffset: (1 - percentage / 100) * perimeter + 'px',
			transition: 'stroke-dashoffset 0.6s ease 0s, stroke 0.6s ease'
		};
	}

	function renderCircle (tableName, percentage, stroke) {
		var stroke = stroke || '#00d6ff';
		var $chart = $(tableName);
		var $track = $chart.find('.circle-chart-track');
		var $path = $chart.find('.circle-chart-path');
		var $p = $chart.parent('.circle-chart-box').find('p');

		$chart.parent('.circle-chart-box').css({
			width: width,
			height: width
		});
		$track.attr('d', getTrackPath());
		$track.attr('stroke-width', relativeStrokeWidth);
		$track.attr('stroke', 'rgba(255, 255, 255, .1)');

		$path.attr('d', getTrackPath());
		$path.attr('stroke-width', relativeStrokeWidth);
		$path.attr('stroke', stroke);
		$path.css(getCirclePathStyle(percentage));
		$p.html(percentage.toFixed(2) + '%');
	}

	renderCircle('#personalBadChart', 5.00, '#ea1159');
	renderCircle('#mediaBadChart', 88.39);
	// showLoading('#generalPublicSentiment')
}

// 个人舆情数
function renderPersonalPublicSentiment () {
	var data = [
		{ date: '七月', notBad: 87053, bad: 3270 },
		{ date: '八月', notBad: 89157, bad: 2730 },
		{ date: '九月', notBad: 28161, bad: 847 }
	]
	var $chart = $('#personalPublicSentimentChart');
	var $bar = $chart.find('.bar-list');
	var str = '';
	var max = 0;
	data.forEach(function (item) {
		var value = item.notBad + item.bad;
		max = max <= value ? value : max;
	});
	var max_temp = Math.ceil(max);
	max_temp = max_temp.toString();
	var length = max_temp.length;
	var first = parseInt(max_temp[0]);
	if (first === '-') {
		max = 0;
	} else if (first > 0) {
		if (length === 1) {
			max = 10;
		} else {
			max = (first + 1) * Math.pow(10, length - 1);
		}
	}
	data.forEach(function (item) {
		var notBadRate = 0;
		var badRate = 0;
		notBadRate = parseFloat((item.notBad / max * 100).toFixed(2));
		badRate = parseFloat((item.bad / max * 100).toFixed(2));
		str += '<div class="bar-item flex justify-content-space-between align-items-center">';
		str += '	<div class="bar-col-1">'+ item.date +'</div>';
		str += '	<div class="bar-col-2">';
		str += '		<div class="bar-bg">';
		str += '			<div class="bar bg-blue" style="width: '+ notBadRate +'%"></div>';
		str += '			<div class="bar bg-red" style="left: '+ notBadRate +'%; width: '+ badRate +'%;"></div>';
		str += '		</div>';
		str += '	</div>';
		str += '	<div class="bar-col-3">';
		str += '		<span class="color-blue">'+ item.notBad +'</span><span class="bar-split">/</span><span class="color-red">'+ item.bad +'</span>';
		str += '	</div>';
		str += '</div>';
	});
	$bar.empty().append(str);
}

// 媒体舆情数 
function renderMediaPublicSentiment () {
	var data = [
		{ date: '七月', notBad: 5206, bad: 1688 },
		{ date: '八月', notBad: 6237, bad: 2408 },
		{ date: '九月', notBad: 2732, bad: 1440 }
	]
	var $chart = $('#mediaPublicSentimentChart');
	var $bar = $chart.find('.bar-list');
	// var $stack = $chart.find('.stack-list');
	var str = '';
	var max = 0;
	data.forEach(function (item) {
		var value = item.notBad + item.bad;
		max = max <= value ? value : max;
	});

	var max_temp = Math.ceil(max);
	max_temp = max_temp.toString();
	var length = max_temp.length;
	var first = parseInt(max_temp[0]);
	if (first === '-') {
		max = 0;
	} else if (first > 0) {
		if (length === 1) {
			max = 10;
		} else {
			max = (first + 1) * Math.pow(10, length - 1);
		}
	}
	data.forEach(function (item) {
		var notBadRate = 0;
		var badRate = 0;
		notBadRate = parseFloat((item.notBad / max * 100).toFixed(2));
		badRate = parseFloat((item.bad / max * 100).toFixed(2));
		str += '<div class="bar-item flex justify-content-space-between align-items-center">';
		str += '	<div class="bar-col-1">'+ item.date +'</div>';
		str += '	<div class="bar-col-2">';
		str += '		<div class="bar-bg">';
		str += '			<div class="bar bg-blue" style="width: '+ notBadRate +'%"></div>';
		str += '			<div class="bar bg-red" style="left: '+ notBadRate +'%; width: '+ badRate +'%;"></div>';
		str += '		</div>';
		str += '	</div>';
		str += '	<div class="bar-col-3">';
		str += '		<span class="color-blue">'+ item.notBad +'</span><span class="bar-split">/</span><span class="color-red">'+ item.bad +'</span>';
		str += '	</div>';
		str += '</div>';
	});

	$bar.empty().append(str);
}

function renderInfoList () {

}

function renderChinaChart () {
	function randomData() {  
		return Math.round(Math.random()*500);  
	}
	var data = [  
        {name: '北京',value: 100 },{name: '天津',value: randomData() },  
        {name: '上海',value: randomData() },{name: '重庆',value: randomData() },  
        {name: '河北',value: randomData() },{name: '河南',value: randomData() },  
        {name: '云南',value: randomData() },{name: '辽宁',value: randomData() },  
        {name: '黑龙江',value: randomData() },{name: '湖南',value: randomData() },  
        {name: '安徽',value: randomData() },{name: '山东',value: randomData() },  
        {name: '新疆',value: randomData() },{name: '江苏',value: randomData() },  
        {name: '浙江',value: randomData() },{name: '江西',value: randomData() },  
        {name: '湖北',value: randomData() },{name: '广西',value: randomData() },  
        {name: '甘肃',value: randomData() },{name: '山西',value: randomData() },  
        {name: '内蒙古',value: randomData() },{name: '陕西',value: randomData() },  
        {name: '吉林',value: randomData() },{name: '福建',value: randomData() },  
        {name: '贵州',value: randomData() },{name: '广东',value: randomData() },  
        {name: '青海',value: randomData() },{name: '西藏',value: randomData() },  
        {name: '四川',value: randomData() },{name: '宁夏',value: randomData() },  
        {name: '海南',value: randomData() },{name: '台湾',value: randomData() },  
        {name: '香港',value: randomData() },{name: '澳门',value: randomData() },
        {name: '南海诸岛', value: 0} 
    ];
    var myChart = echarts.init(document.getElementById('chinaChart'));
    var winWidth = window.innerWidth;
    var option = {
    	grid: {
    		width: '50%',
    		height: '50%'
    	},
    	tooltip: {
            show: true,
            formatter: function (params) {
                var labelFont = winWidth > 2651 ? '36px' : '18px';
                var textFont = winWidth > 2651 ? '28px' : '14px';
                var count = 0;
                data.forEach(function (item) {
                    count += item.value
                });
                var value = params.data && params.data['value'] ? params.data['value'] : 0;
                var rate = value ? (value / count * 100).toFixed(2) : 0;
                if (params.data) {
                    if (params.data['show'] === false) {
                        return '';
                    }
                    return '<span style="font-size: '+ labelFont +';">' + params.name + '</span><br><span style="font-size: '+ textFont +';">' + '认证车主数量：' + value + '<br>' + '认证车主占比：' + rate + '%</span>'
                } else {
                    return '';
                }
            },
            textStyle: {
                fontSize: winWidth > 2561 ? 28 : 14
            }
        },
    	visualMap: {
			type: 'continuous',
			text: ['高', '低'],
			showLabel: true,
			seriesIndex: [0],
			textStyle: {
				color: 'rgba(255, 255, 255, 0.5)'
			},
			inRange: {
				// color: ['#161e25', '#00c0e5']
				color: ['#163643', '#182f3a', '#144554', '#0d7f98', '#00c0e5']
			},
			left: 10,
			bottom: 20
		},
		geo: {
			show: true,
			roam: false,
			map: 'china',
			itemStyle: {
				areaColor: 'rgba(0, 0, 0, 0)',
				// borderWidth: 2,
                // borderColor: '#00d6ff',
                emphasis: {
                	show: false
                }
			},
			label: {
				show: false,
				emphasis: {
					show: false
				}
			},
		},
		series: [{
			map: 'china',
			type: 'map',
			roam: false,
			geoIndex: 1,
			label: {
				show: false,
				emphasis: {
					show: false
				}
			},
			itemStyle: {
				opacity: 0.6,
				borderColor: '#000000',
                borderWidth: 1,
				emphasis: {
					areaColor: '#00d6ff'
				}
			},
			data: data
		}],
		textStyle: {
            fontSize: winWidth > 2561 ? 32 : 12
        }
    };
    myChart.setOption(option);
    $(window).resize(function () {
    	winWidth = window.innerWidth;
    	myChart.setOption({
    		tooltip: {
	            show: true,
	            formatter: function (params) {
	                var labelFont = winWidth > 2651 ? '36px' : '18px';
	                var textFont = winWidth > 2651 ? '28px' : '14px';
	                var count = 0;
	                data.forEach(function (item) {
	                    count += item.value
	                });
	                var value = params.data && params.data['value'] ? params.data['value'] : 0;
	                var rate = value ? (value / count * 100).toFixed(2) : 0;
	                if (params.data) {
	                    if (params.data['show'] === false) {
	                        return '';
	                    }
	                    return '<span style="font-size: '+ labelFont +';">' + params.name + '</span><br><span style="font-size: '+ textFont +';">' + '认证车主数量：' + value + '<br>' + '认证车主占比：' + rate + '%</span>'
	                } else {
	                    return '';
	                }
	            },
	            textStyle: {
	                fontSize: winWidth > 2561 ? 28 : 14
	            }
	        },
    		textStyle: {
	            fontSize: winWidth > 2561 ? 32 : 12
	        }
    	})
		myChart.resize()
	});
}

function renderCompareAnaylsis () {
	function randomData() {  
		return parseFloat((Math.random() * 5).toFixed(2));  
	}

	function getNum () {
		return Math.round(Math.random() * 50);
	}

	function getRate () {
		return parseFloat((Math.random() * 100).toFixed(2))
	}

	var seriesData = [
		{ series: '欧蓝德',  score: randomData(), personalBadRate: getRate(), mediaBadRate: getRate(), complaintCount: getNum() },
		{ series: '帕杰罗劲畅',  score: randomData(), personalBadRate: getRate(), mediaBadRate: getRate(), complaintCount: getNum() },
		{ series: '劲炫ASX',  score: randomData(), personalBadRate: getRate(), mediaBadRate: getRate(), complaintCount: getNum() },
	]
	render();

	function render () {
		var str = '';
		var $container = $('#compareList');
		$container.empty();
		str += '<div class="swiper-wrapper">';
		seriesData.forEach(function (item, index) {
			str += '<div class="swiper-slide swiper-no-swiping compare-item flex">';
			str += '	<div class="compare-col compare-col-left">';
			str += '		<div class="compare-header flex flex-column justify-content-center align-items-center">';
			str += '			<img src="'+ imageSrc +'/images/board/pic-car-1.png" alt="">';
			str += '			<span>'+ item.series +'</span>';
			str += '		</div>';
			str += '		<div class="compare-row flex justify-content-center align-items-center personalBadRate"><span class="">'+ item.personalBadRate +'%</span></div>';
			str += '		<div class="compare-row flex justify-content-center align-items-center mediaBadRate"><span class="">'+ item.mediaBadRate +'%</span></div>';
			str += '		<div class="compare-row flex justify-content-center align-items-center complaintCount"><span class="">'+ item.complaintCount +'</span></div>';
			str += '		<div class="compare-row flex justify-content-center align-items-center score"><span class="">'+ item.score +'</span></div>';
			str += '	</div>';
			str += '	<div class="compare-col compare-col-center">';
			str += '		<div class="compare-header flex flex-column justify-content-center align-items-center">';
			str += '			<img class="compare-vs" src="'+ imageSrc +'/images/board/pic-vs.png" alt="">';
			str += '		</div>';
			str += '		<div class="compare-row flex justify-content-center align-items-center">个人舆情负面率</div>';
			str += '		<div class="compare-row flex justify-content-center align-items-center">媒体舆情负面率</div>';
			str += '		<div class="compare-row flex justify-content-center align-items-center">投诉量</div>';
			str += '		<div class="compare-row flex justify-content-center align-items-center">口碑评分</div>';
			str += '	</div>';
			str += '	<div class="compare-col compare-col-right">';
			str += '		<div class="swiper-container itemSwiper">';
			str += '			<div class="swiper-wrapper">';
			var data = [
				{ series: '奇骏',  score: randomData(), personalBadRate: getRate(), mediaBadRate: getRate(), complaintCount: getNum() },
				{ series: '宝沃BX7',  score: randomData(), personalBadRate: getRate(), mediaBadRate: getRate(), complaintCount: getNum() },
				{ series: '起亚K5',  score: randomData(), personalBadRate: getRate(), mediaBadRate: getRate(), complaintCount: getNum() },
				{ series: '宝来',  score: randomData(), personalBadRate: getRate(), mediaBadRate: getRate(), complaintCount: getNum() }
			];
			data.forEach(function(jItem, jIndex) {
				function renderColor (key, item1, item2) {
					var value1 = item1[key];
					var value2 = item2[key];
					return value1 > value2 ? 'color-red' : value1 < value2 ? 'color-green' : '';
				}

				var personalBadRateColor = renderColor('personalBadRate', jItem, item);
				var mediaBadRateColor = renderColor('mediaBadRate', jItem, item);
				var complaintCountColor = renderColor('complaintCount', jItem, item);
				var scoreColor = renderColor('score', jItem, item);

				str += '		<div class="swiper-slide swiper-no-swiping">'
				str += '			<div class="compare-header flex flex-column justify-content-center align-items-center">';
				str += '				<img src="'+ imageSrc +'/images/board/pic-car-2.png" alt="">';
				str += '				<span>'+ jItem.series +'</span>';
				str += '			</div>';
				str += '			<div class="compare-row flex justify-content-center align-items-center personalBadRate" data-color="'+ personalBadRateColor +'"><span class="'+ personalBadRateColor +'">'+ jItem.personalBadRate +'%</span></div>';
				str += '			<div class="compare-row flex justify-content-center align-items-center mediaBadRate" data-color="'+ mediaBadRateColor +'"><span class="'+ mediaBadRateColor +'">'+ jItem.mediaBadRate +'%</span></div>';
				str += '			<div class="compare-row flex justify-content-center align-items-center complaintCount" data-color="'+ complaintCountColor +'"><span class="'+ complaintCountColor +'">'+ jItem.complaintCount +'</span></div>';
				str += '			<div class="compare-row flex justify-content-center align-items-center score" data-color="'+ scoreColor +'"><span class="'+ scoreColor +'">'+ jItem.score +'</span></div>';
				str += '		</div>';
			});
			str += '			</div>';
			str += '		</div>';
			str += '	</div>';
			str += '</div>';
		});
		str += '</div>';
		$container.append(str);
		renderItemSwiper()
		renderSwiper();
	}

	function renderItemSwiper () {
		var swiper = new Swiper('.itemSwiper', {
			slidesPerView: 1,
			spaceBetween: 0,
			// loop: true,
			autoplay: {
				delay: 2000
				// delay: 30 * 1000
			},
			on: {
				slideChangeTransitionEnd: function() {
					var $left = $(this.$el).parents('.compare-item').find('.compare-col-left');
					var $right = $(this.$el).find('.swiper-slide-active');
					var personalBadRateColorRight = $right.find('.personalBadRate').data('color');
					var mediaBadRateColorRight = $right.find('.mediaBadRate').data('color');
					var complaintCountColorRight = $right.find('.complaintCount').data('color');
					var scoreColorRight = $right.find('.score').data('color');

					function renderColor (color) {
						return color === 'color-red' ? 'color-green' : color === 'color-green' ? 'color-red' : '';
					}

					$left.find('.personalBadRate span').attr('class', renderColor(personalBadRateColorRight));
					$left.find('.mediaBadRate span').attr('class', renderColor(mediaBadRateColorRight));
					$left.find('.complaintCount span').attr('class', renderColor(complaintCountColorRight));
					$left.find('.score span').attr('class', renderColor(scoreColorRight));
    			},
    			resize: function () {
    				var self = this;
    				setTimeout(function () {
						var width = $(self.$el).parents('.compare-item').find('.compare-col-left').width();
    					self.params.width = width;
    					self.update();
    				}, 50);
    			}
			}
		});
	}

	function renderSwiper () {
		var swiper = new Swiper('#compareList', {
			slidesPerView: 2,
			spaceBetween: 0,
			// loop: true,
			autoplay: {
				delay: 10000
				// delay: 2 * 60 * 1000
			},
			on: {
				resize: function () {
					var width = $(this.$el).width();
					this.params.width = width;
					this.update();
				}
			}
		});
	}
}

function renderSeriesKoubeiChart () {
	var seriesData = [
		{ series: '欧蓝德', score: 4.55, type: '小型SUV', bad: 11, total: 90 },
		{ series: '帕杰罗劲畅', score: 4.83, type: '大型SUV', bad: 4, total: 45  },
		{ series: '劲炫ASX', score: 4.60, type: '小型SUV', bad: 16, total: 23  },
		{ series: '祺智PHEV', score: 3.32, type: '小型SUV', bad: 21, total: 74  },
		{ series: '奕歌', score: 5, type: '小型SUV', bad: 8, total: 111  }
	];

	render();

	function render () {
		var str = '';
		var $container = $('#seriesKoubeiChart');
		$container.empty();
		str += '<div class="swiper-wrapper">';
		seriesData.forEach(function (item, index) {
			// 计算公式：-45 + 270 * (score / 5)
			var score = item.score || 0;
			var offset = -45 + 270 * (score / 5);
			str += '';
			str += '<div class="swiper-slide swiper-no-swiping" id="koubeiItem'+ index +'">';
			str += '	<div class="mark-container flex flex-column justify-content-center align-items-center">';
			str += '		<div class="mark">';
			str += '			<div class="ring">';
			str += '				<div class="pointer" style="transform: rotate('+ offset +'deg)"></div>';
			str += '			</div>';
			str += '			<div class="mark-entity flex flex-column justify-content-center align-items-center">';
			str += '				<p class="mark-score">'+ item.score +'</p>';
			str += '				<p class="mark-title">口碑评分</p>';
			str += '			</div>';
			str += '		</div>';
			str += '		<div class="mark-label">'+ item.series +'</div>';
			str += '		<div class="mark-info">';
			str += '			<span class="color-white series">'+ item.type +'：</span><span class="color-white">'+ item.bad +'</span>/<span>'+ item.total +'</span>';
			str += '		</div>';
			str += '	</div>';
			str += '	<div class="radar-container flex flex-column justify-content-center align-items-center">';
			str += '		<div class="radar"></div>';
			str += '		<p class="radar-label">'+ item.series +'</p>';
			str += '	</div>';
			str += '</div>';
		});
		str += '</div>';
		$container.append(str);
		seriesData.forEach(function (item, index) {
			renderRadar(item, index)
		});
		renderSwiper();
	}

	function renderSwiper () {
		var winWidth = window.innerWidth;
		var num = winWidth >= 1920 ? 3 : 2;
		// var num = winWidth <= 1366 ? 2 : 3;
		var swiper = new Swiper('#seriesKoubeiChart', {
			slidesPerView: num,
			spaceBetween: 0,
			// loop: true,
			autoplay: {
				delay: 10000
				// delay: 2 * 60 * 1000
			},
			on: {
				resize: function () {
					var winWidth = window.innerWidth;
					var num = winWidth >= 1920 ? 3 : 2;
					// var num = winWidth <= 1366 ? 2 : 3;
					this.params.slidesPerView = num;
					this.update()
					// renderSwiper();
				}
			}
		});
	}

	function renderRadar (item, index) {
		var winWidth = window.innerWidth;
		var commonOption = {
			tooltip: {
				position: ['0%', '-50%'],
                textStyle: {
                    fontSize: winWidth > 2561 ? 28 : 14
                }
			},
			grid: {
				width: '80%',
			},
			radar: {
				name: {
					fontSize: winWidth > 2561 ? 20 : 10,
					lineHeight: winWidth > 2561 ? 30 : 15,
					// fontSize: 10,
					// lineHeight: 15,
					formatter: formatter,
					color: 'rgba(255, 255, 255, 0.5)',
					rich: {
						align: 'center'
					}
				},
				splitArea: {
					show: false
				},
				indicator: [],
				// radius: 50,
				radius: winWidth > 2561 ? 100 : 50,
				splitLine: {
					lineStyle: {
						color: 'rgba(255, 255, 255, 0.3)'
					}
				},
				axisLine: {
					lineStyle: {
						color: 'rgba(255, 255, 255, 0.3)'
					}
				}
			}
		}

		var data = [
			{ series: item.series, param: '空调', score: randomData() },
			{ series: item.series, param: '劲力', score: randomData() },
			{ series: item.series, param: '操控', score: randomData() },
			{ series: item.series, param: '油耗', score: randomData() },
			{ series: item.series, param: '内饰', score: randomData() },
			{ series: item.series, param: '外观', score: randomData() },
			{ series: item.series, param: '性价比', score: randomData() },
			{ series: item.series, param: '舒适度', score: randomData() },
			{ series: item.series, param: '配置', score: randomData() }
		];
		var title = '';
		var indicatorArr = [];
		var indicator = [];
		data.forEach(function (item) {
			title = item.series;
			indicatorArr.indexOf(item.param) < 0 && indicatorArr.push(item.param);
		});
		indicatorArr.forEach(function (item) {
			indicator.push({
				name: item,
				max: 5
			});
		});
		var seriesData = [];
		data.forEach(function (item) {
			seriesData.push(item.score);
		});
		var chart = echarts.init($('#koubeiItem'+ index +' .radar')[0]);
		var option = $.extend(true, {}, commonOption);
		option.radar.indicator = indicator;
		option.series = [{
			name: title,
			type: 'radar',
			itemStyle: {
				color: '#00d6ff',
			},
			areaStyle: {
				normal: {
					opacity: 0.5
				}
			},
			lineStyle: {
				normal: {
			        width: 1,
			        opacity: 0.5
			    }
			},
			data: [{
				value : seriesData,
				name : title,
			}],
			label: {
				// show: true
			}
		}];
		chart.setOption(option);
		$(window).resize(function() {
			winWidth = window.innerWidth;
			chart.setOption({
				tooltip: {
	                textStyle: {
	                    fontSize: winWidth > 2561 ? 28 : 14
	                }
				},
				radar: {
					name: {
						fontSize: winWidth > 2561 ? 20 : 10,
						lineHeight: winWidth > 2561 ? 30 : 15,
					},
					radius: winWidth > 2561 ? 100 : 50,
				}
			})
			chart.resize();
		});
		$('#koubeiItem'+ index +' .radar-label').html(title);
	}

	function randomData() {  
		return parseFloat((Math.random() * 5).toFixed(2));  
	}

	function formatter (value) {
		var newStr = '';
		var start, end;
		var name_len = value.length;
		var max_name = 2;
		var new_row = Math.ceil(name_len / max_name);
		if (name_len > max_name) {
			for (var i = 0; i < new_row; i++) {
				var old = '';
				start = i * max_name;
				end = start + max_name;
				if (i === new_row - 1) {
					old = value.substring(start);
				} else {
					old = value.substring(start,end) + '\n';
				}
				newStr += old;
			}
		} else {
			newStr = value;
		}
		return newStr;
	}

}

function renderTime () {
	var date = new Date();
	date.setMinutes(0);
	date.setSeconds(0);
	var time = date.format('yyyy-MM-dd hh:mm:ss');
	$('#time').html(time);
}

function init () {
	renderTime();
	renderGeneralPublicSentiment();
	renderPersonalPublicSentiment();
	renderMediaPublicSentiment();
	renderInfoList();
	renderCompareAnaylsis();
	renderChinaChart();
	renderSeriesKoubeiChart();
}

// 定时每个小时取一次数据
var timestamp = 60 * 60 * 1000;
var mainInterval = setInterval(function () {
	init();
}, timestamp);

var timeInterval = setInterval(function () {
	renderTime();
}, 60 * 1000);

$(function () {
	init();
});

function showLoading (container, x, y) {
	if ($(container + '_loading').length) return;
	x = x || '40px';
	y = y || '40px';
	var style = '"width: '+ x +'; height: ' + y +'; display: block; position: absolute; left: 50%;top: 50%; margin-left: '+ (-parseInt(x) / 2) +'px; margin-top: '+ (-parseInt(y) / 2) +'px; border: 5px solid rgba(0, 214, 255); border-right: 5px solid transparent; border-radius: 50%;"';
	var str = '';
	var type = container[0];
	var name = container.slice(1);
	if (type === '#') {
		str += '<div id="'+ name +'_loading_mask" ';
	} else {
		str += '<div class="'+ name + '_loading_mask' +'" '
	}
	str += 'style="position: absolute; left: 0; top: 0; right: 0; bottom: 0; background-color: rgba(0, 214, 255, 0.1);">';
	str += '<div class="rotate" style='+ style +'></div></div>'
	$(container).addClass('mitsubishi-loading');
	$(container).append(str);
}

function hideLoading (container) {
	$(container + '_loading_mask').remove();
	$(container).removeClass('mitsubishi-loading');
}